<?php

/*
 * This file will query those document routes that are available for the selected documentSetupId.
 * 
 * Created by: Peter Agno Jr.
 * Date created: September 16, 2011
 * 
 * In parameters : documentSetupId
 * Out parameters : Array of routeId and routeName
 */

// Start - Checker for those users who will just go to the page by typing directly in the url.
if ($_POST) {
    // INCLUDES CONFIGURATION VARIABLES FOR DATABASE ACCESS
    include('../includes/siteConfig.php');
    
    // CONNECT TO DATABASE
    $connect = mysql_connect($hostName,$rootName,$dBasePassword) or die ('Unable to connect!');
    mysql_select_db($dBaseName) or die ('Unable to select database!');
    
    // GET VARIABLES VIA POST METHOD
    $documentSetupId = $_POST['documentSetupId'];
    
    // QUERY - GET ALL DOCUMENT ROUTES AVAILABLE FOR DOCUMENTSETUPID
    $query = 
        "
            SELECT * 
            FROM DocumentRoute 
            WHERE documentSetupId = '$documentSetupId' AND routeLastUpdated is NULL
        ";
    
    $result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
    
    // SAVE QUERY RESULTS TO AN ARRAY > $row   
    while ($row = mysql_fetch_array($result)) {
        $jsondata = array();
        $jsondata['routeId'] = $row['routeId'];
        $jsondata['routeName'] = $row['routeName'];

        $feed[] = $jsondata;
    }
    
    echo json_encode($feed);
    
    mysql_free_result($result);
    mysql_close($connect);
}   // End - Checker for those users who will just go to the page by typing directly in the url.
else {
 echo "You are not authorized to view this page. This incident will be reported immediately.";
}
?>
